/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package behaviourdiagram.impl;

import behaviourdiagram.Actuator;
import behaviourdiagram.Behaviour;
import behaviourdiagram.BehaviourOutput;
import behaviourdiagram.BehaviourdiagramPackage;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Behaviour Output</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link behaviourdiagram.impl.BehaviourOutputImpl#getName <em>Name</em>}</li>
 *   <li>{@link behaviourdiagram.impl.BehaviourOutputImpl#getActuator <em>Actuator</em>}</li>
 *   <li>{@link behaviourdiagram.impl.BehaviourOutputImpl#getBehaviour <em>Behaviour</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class BehaviourOutputImpl extends EObjectImpl implements BehaviourOutput {
	/**
   * The default value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
	protected static final String NAME_EDEFAULT = null;

	/**
   * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
	protected String name = NAME_EDEFAULT;

	/**
   * The cached value of the '{@link #getActuator() <em>Actuator</em>}' reference.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getActuator()
   * @generated
   * @ordered
   */
	protected Actuator actuator;

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	protected BehaviourOutputImpl() {
    super();
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	protected EClass eStaticClass() {
    return BehaviourdiagramPackage.Literals.BEHAVIOUR_OUTPUT;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public String getName() {
    return name;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public void setName(String newName) {
    String oldName = name;
    name = newName;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, BehaviourdiagramPackage.BEHAVIOUR_OUTPUT__NAME, oldName, name));
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public Actuator getActuator() {
    if (actuator != null && actuator.eIsProxy())
    {
      InternalEObject oldActuator = (InternalEObject)actuator;
      actuator = (Actuator)eResolveProxy(oldActuator);
      if (actuator != oldActuator)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, BehaviourdiagramPackage.BEHAVIOUR_OUTPUT__ACTUATOR, oldActuator, actuator));
      }
    }
    return actuator;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public Actuator basicGetActuator() {
    return actuator;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public NotificationChain basicSetActuator(Actuator newActuator, NotificationChain msgs) {
    Actuator oldActuator = actuator;
    actuator = newActuator;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, BehaviourdiagramPackage.BEHAVIOUR_OUTPUT__ACTUATOR, oldActuator, newActuator);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public void setActuator(Actuator newActuator) {
    if (newActuator != actuator)
    {
      NotificationChain msgs = null;
      if (actuator != null)
        msgs = ((InternalEObject)actuator).eInverseRemove(this, BehaviourdiagramPackage.ACTUATOR__OUTPUT, Actuator.class, msgs);
      if (newActuator != null)
        msgs = ((InternalEObject)newActuator).eInverseAdd(this, BehaviourdiagramPackage.ACTUATOR__OUTPUT, Actuator.class, msgs);
      msgs = basicSetActuator(newActuator, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, BehaviourdiagramPackage.BEHAVIOUR_OUTPUT__ACTUATOR, newActuator, newActuator));
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public Behaviour getBehaviour() {
    if (eContainerFeatureID() != BehaviourdiagramPackage.BEHAVIOUR_OUTPUT__BEHAVIOUR) return null;
    return (Behaviour)eContainer();
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public NotificationChain basicSetBehaviour(Behaviour newBehaviour, NotificationChain msgs) {
    msgs = eBasicSetContainer((InternalEObject)newBehaviour, BehaviourdiagramPackage.BEHAVIOUR_OUTPUT__BEHAVIOUR, msgs);
    return msgs;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public void setBehaviour(Behaviour newBehaviour) {
    if (newBehaviour != eInternalContainer() || (eContainerFeatureID() != BehaviourdiagramPackage.BEHAVIOUR_OUTPUT__BEHAVIOUR && newBehaviour != null))
    {
      if (EcoreUtil.isAncestor(this, newBehaviour))
        throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
      NotificationChain msgs = null;
      if (eInternalContainer() != null)
        msgs = eBasicRemoveFromContainer(msgs);
      if (newBehaviour != null)
        msgs = ((InternalEObject)newBehaviour).eInverseAdd(this, BehaviourdiagramPackage.BEHAVIOUR__OUTPUTS, Behaviour.class, msgs);
      msgs = basicSetBehaviour(newBehaviour, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, BehaviourdiagramPackage.BEHAVIOUR_OUTPUT__BEHAVIOUR, newBehaviour, newBehaviour));
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
    switch (featureID)
    {
      case BehaviourdiagramPackage.BEHAVIOUR_OUTPUT__ACTUATOR:
        if (actuator != null)
          msgs = ((InternalEObject)actuator).eInverseRemove(this, BehaviourdiagramPackage.ACTUATOR__OUTPUT, Actuator.class, msgs);
        return basicSetActuator((Actuator)otherEnd, msgs);
      case BehaviourdiagramPackage.BEHAVIOUR_OUTPUT__BEHAVIOUR:
        if (eInternalContainer() != null)
          msgs = eBasicRemoveFromContainer(msgs);
        return basicSetBehaviour((Behaviour)otherEnd, msgs);
    }
    return super.eInverseAdd(otherEnd, featureID, msgs);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
    switch (featureID)
    {
      case BehaviourdiagramPackage.BEHAVIOUR_OUTPUT__ACTUATOR:
        return basicSetActuator(null, msgs);
      case BehaviourdiagramPackage.BEHAVIOUR_OUTPUT__BEHAVIOUR:
        return basicSetBehaviour(null, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
    switch (eContainerFeatureID())
    {
      case BehaviourdiagramPackage.BEHAVIOUR_OUTPUT__BEHAVIOUR:
        return eInternalContainer().eInverseRemove(this, BehaviourdiagramPackage.BEHAVIOUR__OUTPUTS, Behaviour.class, msgs);
    }
    return super.eBasicRemoveFromContainerFeature(msgs);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
    switch (featureID)
    {
      case BehaviourdiagramPackage.BEHAVIOUR_OUTPUT__NAME:
        return getName();
      case BehaviourdiagramPackage.BEHAVIOUR_OUTPUT__ACTUATOR:
        if (resolve) return getActuator();
        return basicGetActuator();
      case BehaviourdiagramPackage.BEHAVIOUR_OUTPUT__BEHAVIOUR:
        return getBehaviour();
    }
    return super.eGet(featureID, resolve, coreType);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public void eSet(int featureID, Object newValue) {
    switch (featureID)
    {
      case BehaviourdiagramPackage.BEHAVIOUR_OUTPUT__NAME:
        setName((String)newValue);
        return;
      case BehaviourdiagramPackage.BEHAVIOUR_OUTPUT__ACTUATOR:
        setActuator((Actuator)newValue);
        return;
      case BehaviourdiagramPackage.BEHAVIOUR_OUTPUT__BEHAVIOUR:
        setBehaviour((Behaviour)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public void eUnset(int featureID) {
    switch (featureID)
    {
      case BehaviourdiagramPackage.BEHAVIOUR_OUTPUT__NAME:
        setName(NAME_EDEFAULT);
        return;
      case BehaviourdiagramPackage.BEHAVIOUR_OUTPUT__ACTUATOR:
        setActuator((Actuator)null);
        return;
      case BehaviourdiagramPackage.BEHAVIOUR_OUTPUT__BEHAVIOUR:
        setBehaviour((Behaviour)null);
        return;
    }
    super.eUnset(featureID);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public boolean eIsSet(int featureID) {
    switch (featureID)
    {
      case BehaviourdiagramPackage.BEHAVIOUR_OUTPUT__NAME:
        return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
      case BehaviourdiagramPackage.BEHAVIOUR_OUTPUT__ACTUATOR:
        return actuator != null;
      case BehaviourdiagramPackage.BEHAVIOUR_OUTPUT__BEHAVIOUR:
        return getBehaviour() != null;
    }
    return super.eIsSet(featureID);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public String toString() {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (name: ");
    result.append(name);
    result.append(')');
    return result.toString();
  }

} //BehaviourOutputImpl
